package com.example.employeemanagement.Controller;

import com.example.employeemanagement.entry.Position;
import com.example.employeemanagement.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

// 职位
@RestController
@RequestMapping("/positions")
public class PositionController {
    @Autowired
    private PositionService positionService;

    @GetMapping
    public List<Position> getAllPositions() {
        return positionService.getAllPositions();
    }

    @GetMapping("/{positionId}")
    public Position getPositionById(@PathVariable Integer positionId) {
        return positionService.getPositionById(positionId);
    }

    @PostMapping
    public String addPosition(@RequestBody Position position) {
        return positionService.addPosition(position);
    }

    @PutMapping("/{positionId}")
    public String updatePosition(@PathVariable Integer positionId, @RequestBody Position updatedPosition) {
        updatedPosition.setPosition_id(positionId);
        return positionService.updatePosition(updatedPosition);
    }

    @DeleteMapping("/{positionId}")
    public String deletePosition(@PathVariable Integer positionId) {
        return positionService.deletePosition(positionId);
    }
}